﻿@page "/_Student/Student/Create"
@using WBBvNext.ViewModel._Student.StudentVMs;
@inherits BasePage

<ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
    <Row ItemsPerRow="ItemsPerRow.Two" RowType="RowType.FormRow">

            <BootstrapInput @bind-Value="@Model.Entity.LoginName"  />
            <BootstrapInput @bind-Value="@Model.Entity.Password"  />
            <BootstrapInput @bind-Value="@Model.Entity.Name"  />
            <BootstrapInput @bind-Value="@Model.Entity.CellPhone"  />
            <BootstrapInput @bind-Value="@Model.Entity.ZipCode"  />
            <DateTimePicker @bind-Value="@Model.Entity.EnRollDate"  />
            <WTUploadImage @bind-Value="@Model.Entity.PhotoId" CSKey="School"  />
    <Row ColSpan="2">
            <Transfer @bind-Value="@Model.SelectedStudentMajorIDs" Items="@AllMajors" />
    </Row>
    </Row>
    <div class="modal-footer table-modal-footer">
        <Button Color="Color.Primary" Icon="fa fa-save" Text="@WtmBlazor.Localizer["Sys.Close"]" OnClick="OnClose" />
        <Button Color="Color.Primary" ButtonType="ButtonType.Submit" Icon="fa fa-save" Text="@WtmBlazor.Localizer["Sys.Create"]" IsAsync="true" />
    </div>
</ValidateForm>

@code {

    private StudentVM Model = new StudentVM();
    private ValidateForm vform { get; set; }

    private List<SelectedItem> AllMajors = new List<SelectedItem>();


    protected override async Task OnInitializedAsync()
    {

        AllMajors = await WtmBlazor.Api.CallItemsApi("/api/Student/GetMajors");

        await base.OnInitializedAsync();
    }


    private async Task Submit(EditContext context)
    {
        await PostsForm(vform, "/api/Student/add", (s) => "Sys.OprationSuccess");
    }

    public void OnClose()
    {
        CloseDialog();
    }

}
